/*
 * Copyright (c) 2007 Argonne National Laboratory. All rights reserved.
 */
package ratkit.repast.schedule;

import repast.simphony.engine.environment.RunEnvironment;
import repast.simphony.engine.environment.RunEnvironmentBuilder;
import repast.simphony.engine.environment.Runner;
import repast.simphony.engine.schedule.IScheduleFactory;
import repast.simphony.parameter.EmptyParameters;
import repast.simphony.parameter.Parameters;

/**
 * Builder for creating a RatKitRunEnvironment object.
 * 
 * @author İbrahim Çakırlar
 */
public class RatKitRunEnvironmentBuilder implements RunEnvironmentBuilder {

	/**
	 * Schedule factory for the test environment.
	 */
	private IScheduleFactory scheduleFactory = new RatKitScheduleFactory();
	/**
	 * Runner of the test environment.
	 */
	private Runner runner;
	/**
	 * Decides if the execution is batch or not.
	 */
	private boolean isBatch;

	/**
	 * Parameters instance for the environment
	 */
	private Parameters parameters = new EmptyParameters();

	/**
	 * Creates a RunEnvironmentBuilder that will use the specified schedule
	 * runner to run each run of the simulation.
	 * 
	 * @param runner
	 * @param isBatch
	 *            whether or not this is operating in batch mode.
	 */
	public RatKitRunEnvironmentBuilder(Runner runner, boolean isBatch) {
		this.runner = runner;
		this.isBatch = isBatch;
	}

	/**
	 * Gets the schedule runner used to run each run of the simulation.
	 * 
	 * @return the schedule runner used to run each run of the simulation.
	 */
	public Runner getScheduleRunner() {
		return runner;
	}

	/**
	 * Gets the schedule factory used to create the schedule for simulation
	 * runs.
	 * 
	 * @return the schedule factory used to create the schedule for simulation
	 *         runs.
	 */
	public IScheduleFactory getScheduleFactory() {
		return scheduleFactory;
	}

	/**
	 * Sets the schedule factory used to create the schedule for simulation
	 * runs.
	 * 
	 * @param scheduleFactory
	 *            the new schedule factory
	 */
	public void setScheduleFactory(IScheduleFactory scheduleFactory) {
		this.scheduleFactory = scheduleFactory;
	}

	/**
	 * Gets the parameters to be used in the next simulation run.
	 * 
	 * @return the parameters to be used in the next simulation run.
	 */
	public Parameters getParameters() {
		return parameters;
	}

	/**
	 * Sets the parameters to be used in the next simulation run.
	 * 
	 * @param parameters
	 *            the parameters to be used in the next simulation run.
	 */
	public void setParameters(Parameters parameters) {
		this.parameters = parameters;
	}

	/**
	 * Creates the Runtime to be used for the next simulation run. Each
	 * simulation run gets a new runtime.
	 * 
	 * @return the Runtime to be used for the next simulation run.
	 */
	public RunEnvironment createRunEnvironment() {
		RunEnvironment.init(scheduleFactory.createSchedule(), runner,
				parameters, isBatch);
		return RunEnvironment.getInstance();
	}

	@Override
	public RunEnvironment createRunEnvironmentDistributed(Thread thread) {
		// TODO Auto-generated method stub
		return null;
	}
}
